<%@ Page Language="C#" MasterPageFile="~/Views/Layout.Master" AutoEventWireup="true" 
    Inherits="System.Web.Mvc.ViewPage" 
    Title="Edit Work Order" %>
<%@ Import Namespace="Microsoft.Web.Mvc"%>
<%@ Import Namespace="Headspring.Training.Core.Services"%>
<%@ Import Namespace="Headspring.Training.UI.Models"%>
<%@ Import Namespace="Headspring.Training.Core.Model"%>
<%@ Import Namespace="MvcContrib"%>
<asp:Content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<form action="<%=Url.Action("do") %>" method="post">
    <h3 style="text-align:center;">Work Order # <%=ViewData.Get<WorkOrder>().Number %> (<%=ViewData.Get<WorkOrder>().FriendlyStatus%>)</h3>
    <%=Html.Hidden("workordernumber", ViewData.Get<WorkOrder>().Number)%>
    <table border="0" cellpadding="2" width="100%">
        <tr>
            <td class="label">Creator:</td><td class="formfield"><%=Html.Encode(ViewData.Get<WorkOrder>().Creator.GetFullName()) %></td>
        </tr>
        <tr>
            <td class="label">Assigned To:</td><td class="formfield"><%=Html.DropDownList("assignee", ViewData.Get<EmployeeSelectList>()) %></td>
        </tr>
        <tr>
            <td class="label">Title:</td><td class="formfield"><%=Html.TextBox("title", ViewData.Get<WorkOrder>().Title)%></td>
        </tr>
        <tr>
            <td class="label">Description:</td><td class="formfield"><%=Html.TextArea("description", ViewData.Get<WorkOrder>().Description, 5, 40, new { maxlenghth = 4000})%></td>
        </tr>
        <tr>
            <td colspan="2">created: <%=ViewData.Get<WorkOrder>().CreatedDate.ToString()%> completed: <%=ViewData.Get<WorkOrder>().CompletedDate.ToString()%></td>
        </tr>
        <tr>
            <td colspan="2" style="width:100%;padding:5px;background-color:yellow; text-align:right;" nowrap>
                <%foreach (var command in ViewData.Get<IStateCommand[]>())
                    {
                        Response.Write(Html.SubmitButton("command", command.TransitionVerbPresentTense));
                    } %>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="width:100%">
                <asp:DataGrid ID="historyGrid" runat="server" AutoGenerateColumns="false" Width="100%">
                    <Columns>
                        <asp:BoundColumn HeaderText="Date" DataField="ChangeDate" />
                        <asp:TemplateColumn HeaderText="Name" >
                            <ItemTemplate>
                            <asp:Label runat="server" Text='<%# ((HistoryEntry)Container.DataItem).GetFullName() %>' />
                            </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:BoundColumn HeaderText="Begin Status" DataField="BeginStatus" />
                        <asp:BoundColumn HeaderText="End Status" DataField="EndStatus" />
                    </Columns>
                </asp:DataGrid>
            </td>
        </tr>
    </table>
</form>
</asp:Content>
<script runat="server">

    protected override void OnLoadComplete(EventArgs e)
    {
        historyGrid.DataSource = ViewData.Get<WorkOrder>().GetHistory();
        historyGrid.DataBind();
    }

</script>